package com.example.apple.ddhr_new.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.activity.LoginActivity;
import com.activity.PersonalActivity;
import com.example.apple.ddhr_new.MainActivity;
import com.example.apple.ddhr_new.R;

import androidx.fragment.app.Fragment;


public class ActivityUtil {


    public static  String PARAM_KEY = "PARAM_KEY";
    public  static  void  startActivity(Context context,Class target){

        startActivity(context,target,null);

    }
    public  static  void  startActivity(Context context, Class target, Bundle param){


        Intent intent = new Intent(context,target);


        if(null==param){

        }else {
            intent.putExtras(param);
        }
        context.startActivity(intent);

    }
    public  static  void  startActivity(Activity context, Class target, Bundle param,int requestCode){


        Intent intent = new Intent(context,target);


        if(null==param){

        }else {
            intent.putExtras(param);
        }
        context.startActivityForResult (intent,requestCode);

    }
    public  static  void  startActivity(Fragment context, Class target, Bundle param, int requestCode){


        Intent intent = new Intent(context.getContext(),target);


        if(null==param){

        }else {
            intent.putExtras(param);
        }
        context.startActivityForResult (intent,requestCode);

    }
    public  static  void  startLoginActivity(Context context){

        Intent intent = new Intent(context,LoginActivity.class);



        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

        context.startActivity(intent);

    }
    public  static  void  startMainActivity(Context context){

        Intent intent = new Intent(context,MainActivity.class);

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);


    }

    public  static  void  startPersonalActivity(Context context){

        Intent intent = new Intent(context,PersonalActivity.class);



        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

        context.startActivity(intent);

        ((Activity)context).overridePendingTransition(R.anim.on_activity_reopen, R.anim.on_activity_close);

    }
    public  static  void  popMainActivity(Context context){

        Intent intent = new Intent(context,MainActivity.class);



        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

        context.startActivity(intent);

        ((Activity)context).overridePendingTransition(R.anim.on_activity_reopen, R.anim.on_activity_close);

    }


}
